/*
define input parameter {2} as date  .
define input parameter {3} as date .
define input parameter {4} like hwom_team.
define input parameter {5} like hwom_team.
*/

 
 
define variable vdb like ad_name_control initial "".
 
for first ad_mstr no-lock where ad_addr = "~~reports".
end.
if avail ad_mstr then do:
    assign vdb =  ad_name_control .
end.

 /* find code_mstr NO-LOCK WHERE code_fldname = "exptab2csv" and code_value = "output" no-error. */
/* if avail code_mstr then do:                                                                  */
/*     assign {1} = code_cmmt.                                                              */
/* end.                                                                                         */

if {2} = ? then assign {2} = today - 1.
if {3} = ? then assign {3} = today - 1.
if {5} = "" then assign {5} = "zzzzzz".
output to value({1} + vdb + "sflog.log").
    put vdb format "x(" + string(length(trim(vdb))) +  ")" ","
        string(year({2}),"9999") + "-" + string(month({2}),"99") + "-" + string(day({2}),"99") format "x(10)" ","
        string(year({3}),"9999") + "-" + string(month({3}),"99") + "-" + string(day({3}),"99") format "x(10)" ","
        {4} format "x(" + string(length(trim({4}))) +  ")"  ","
        {5} format "x(" + string(length(trim({5}))) +  ")"  skip.
output close.

output to value({1} + vdb + "hwop_det.csv").
FOR EACH hwop_det no-lock where hwop_date >= {2} and hwop_date <= {3} and hwop_team >= {4} and hwop_team <= {5} :
    put vdb "," .
    if hwop_date  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwop_date ),"9999") + "-" + string(month(hwop_date ),"99") + "-" + string(day(hwop_date ),"99") format "x(10)" ",".
    end.
    put trim(hwop_team) format "x(12)" ","
        hwop_ln  format "->>>>9" ","
        hwop_phase      ","
        hwop_emp_id     ","
        hwop_emp_name   ","
        hwop_tag        ","
        hwop_status     ","
        hwop__chr01      ","
        hwop__chr02      ",".
    if hwop__dte01  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwop__dte01),"9999") + "-" + string(month(hwop__dte01),"99") + "-" + string(day(hwop__dte01),"99") format "x(10)" ",".
    end.
    if hwop__dte02 = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwop__dte02),"9999") + "-" + string(month(hwop__dte02),"99") + "-" + string(day(hwop__dte02),"99") format "x(10)" ",".
    end.
    put 
         hwop__dec01    format "->>>>>>>>9.9<<<<<<" ","
         hwop__dec02    format "->>>>>>>>9.9<<<<<<" ","
         hwop__dec03    format "->>>>>>>>9.9<<<<<<" ","
         hwop__int01    format "->>>>>>>>9" "," 
         hwop__int02    format "->>>>>>>>9" "," 
         hwop__log01       "," 
         hwop__log02 
         skip.
end.
output close.

output to value({1} + vdb + "hwoa_det.csv").
FOR EACH hwoa_det no-lock where hwoa_date >= {2} and hwoa_date <= {3} and hwoa_team >= {4} and hwoa_team <= {5} :
    put vdb "," .
    if hwoa_date  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwoa_date ),"9999") + "-" + string(month(hwoa_date ),"99") + "-" + string(day(hwoa_date ),"99") format "x(10)" ",".
    end.
    put trim(hwoa_team) format "x(12)" ","
        hwoa_ln  format "->>>>9" ","
        hwoa_phase  ","
        hwoa_part   ","
        hwoa_rsn_code  ","
        hwoa_duty      ","
   """" hwoa_desc      ""","
   """" hwoa_run_aff   ""","
        hwoa_status      ","
   """" hwoa__chr01    ""","
   """" hwoa__chr02    """,".
        if hwoa__dte01  = ? then do:
            put ",".
        end.
        else  do:
            put string(year(hwoa__dte01 ),"9999") + "-" + string(month(hwoa__dte01 ),"99") + "-" + string(day(hwoa__dte01),"99") format "x(10)" ",".
        end.
        if hwoa__dte02  = ? then do:
            put ",".
        end.
        else  do:
            put string(year(hwoa__dte02 ),"9999") + "-" + string(month(hwoa__dte02 ),"99") + "-" + string(day(hwoa__dte02),"99") format "x(10)" ",".
        end.
     put
         hwoa__dec01    format "->>>>>>>>9.9<<<<<<" ","
         hwoa__dec02    format "->>>>>>>>9.9<<<<<<" ","
         hwoa__dec03    format "->>>>>>>>9.9<<<<<<" ","
         hwoa__int01    format "->>>>>>>>9" "," 
         hwoa__int02    format "->>>>>>>>9" "," 
    """" hwoa__log01       """," 
    """" hwoa__log02       """," 
    """" hwoa__chr03       """," 
    """" hwoa__chr04       """," 
    """" hwoa__chr05       """," 
    """" hwoa__chr06       """," 
    """" hwoa__chr07       """," 
    """" hwoa__chr08       """," 
    """" hwoa__chr09       """," 
    """" hwoa__chr10       """," 
         hwoa__dec04    format "->>>>>>>>9.9<<<<<<" ","
         hwoa__dec05    format "->>>>>>>>9.9<<<<<<" ","
         hwoa__dec06    format "->>>>>>>>9.9<<<<<<" ","
         hwoa_aff_run   format "->>>>>>>>9.9<<<<<<" "," 
         skip.
END.
output close.

output to value({1} + vdb + "hwot_det.csv").
FOR EACH hwot_det NO-LOCK WHERE hwot_date >= {2} and hwot_date <= {3} and hwot_team >= {4} and hwot_team <= {5} :
    put vdb ",".
    if hwot_date  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwot_date ),"9999") + "-" + string(month(hwot_date ),"99") + "-" + string(day(hwot_date ),"99") format "x(10)" ",".
    end.
    put   
         trim(hwot_team) format "x(12)" "," 
         hwot_ln   format "->>>>>>9"   "," 
         hwot_phase        "," 
         hwot_status       "," 
         hwot_emp_std     format "->>>>>>9"  "," 
         hwot_emp_act     format "->>>>>>9"  "," 
         hwot_person_std  format "->>>>>>9"  ","
         hwot_person_act  format "->>>>>>9"  ","
    """" hwot_nextday      """," 
         hwot_mshift     format "->>9" ","
    """" hwot_prog       format "x(12)"    """," 
    """" hwot_user1        """," 
    """" hwot_user2        """," 
    """" hwot__chr01       """," 
    """" hwot__chr02       """," 
    """" hwot__chr03       """," 
    """" hwot__chr04       """," 
    """" hwot__chr05       """," .
    if hwot__dte01  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwot__dte01 ),"9999") + "-" + string(month(hwot__dte01 ),"99") + "-" + string(day(hwot__dte01),"99") format "x(10)" ",".
    end.
    if hwot__dte02  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwot__dte02 ),"9999") + "-" + string(month(hwot__dte02 ),"99") + "-" + string(day(hwot__dte02),"99") format "x(10)" ",".
    end.
    put
         hwot__dec01    format "->>>>>>>>9.9<<<<<<" ","
         hwot__dec02    format "->>>>>>>>9.9<<<<<<" ","
         hwot__dec03    format "->>>>>>>>9.9<<<<<<" ","
         hwot__dec04    format "->>>>>>>>9.9<<<<<<" ","
         hwot__dec05    format "->>>>>>>>9.9<<<<<<" ","
         hwot__int01    format "->>>>>>>>9" "," 
         hwot__int02    format "->>>>>>>>9" "," 
         hwot__int03    format "->>>>>>>>9" "," 
         hwot__int04    format "->>>>>>>>9" "," 
         hwot__int05    format "->>>>>>>>9" "," 
    """" hwot__log01       """," 
    """" hwot__log02       """" 
    .
    put skip.

END.
OUTPUT CLOSE.

output to value({1} + vdb + "hwom_det.csv").
FOR EACH hwom_det NO-LOCK WHERE hwom_date >= {2} and hwom_date <= {3} and hwom_team >= {4} and hwom_team <= {5} :
    
    put vdb ",".
    if hwom_date  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwom_date ),"9999") + "-" + string(month(hwom_date ),"99") + "-" + string(day(hwom_date ),"99") format "x(10)" ",".
    end.
    put   
         trim(hwom_team)  format "x(12)"    "," 
         hwom_phase        "," 
         hwom_ln   format "->>>>>>9"   "," 
         hwom_sn   format "->>>>>>9"   "," 
    """" hwom_lot   """," 
         hwom_nbr          "," 
         hwom_part         "," 
         hwom_op   format "->>>>>>9"   "," 
    """" hwom_wkctr        """," 
    """" hwom_op_desc      """," 
    """" hwom_dept         """," 
         hwom_emp_std     format "->>>>>>9"  "," 
         hwom_emp_act     format "->>>>>>9"  "," 
         hwom_person_std  format "->>>>>>9"  ","
         hwom_person_act  format "->>>>>>9"  ","
         hwom_setup_std   format "->>>>>>9"  ","
         hwom_setup_act   format "->>>>>>9"  ","
         hwom_run_std     format "->>>>>>9.9<<<<<"  "," 
         hwom_run_act     format "->>>>>>9.9<<<<<"  "," 
         hwom_move_std    format "->>>>>>9.9<<<<<"  ","
         hwom_move_act    format "->>>>>>9.9<<<<<"  ","
         hwom_qty_std     format "->>>>>>9.9<<<<<<" ","
         hwom_qty_ord     format "->>>>>>9.9<<<<<<" ","
         hwom_qty_inpt    format "->>>>>>9.9<<<<<<" "," 
         hwom_qty_wip     format "->>>>>>9.9<<<<<<" "," 
         hwom_qty_comp    format "->>>>>>9.9<<<<<<" ","
         hwom_qty_rjct    format "->>>>>>9.9<<<<<<" ","
         hwom_qty_rwrk    format "->>>>>>9.9<<<<<<" ","
    """" hwom_status       """," 
    """" hwom_st_desc      """," 
    """" hwom_vend         """," 
    """" hwom_po_nbr       """," 
    """" hwom_po_line      """," 
         hwom_yield_pct   format "->>>>>>9.9<<<<<<" ","
         hwom_bdn_std     format "->>>>>>9.9<<<<<<" ","
         hwom_bdn_act     format "->>>>>>9.9<<<<<<" ","
         hwom_lbr_std     format "->>>>>>9.9<<<<<<" ","
         hwom_lbr_act     format "->>>>>>9.9<<<<<<" ","
         hwom_sub_std     format "->>>>>>9.9<<<<<<" ","
         hwom_sub_act     format "->>>>>>9.9<<<<<<" ","
         hwom_setup_rte   format "->>>>>9.9<<<<" ","
         hwom_lbr_rate    format "->>>>>>9.9<<<<" ","
         hwom_bdn_pct     format "->>>>>>9.9<<<<" "," 
    """" hwom_PrLine       """," 
    """" hwom_nextday      """," 
         hwom_mshift     format "->>9" ","
         hwom_bdn_rate   format "->>>>>>9.9<<<<" ","
    """" hwom_desc         """," 
    """" hwom_milestone    """," 
    """" hwom_mod_userid   """," .
    if hwom_mod_date  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwom_mod_date ),"9999") + "-" + string(month(hwom_mod_date ),"99") + "-" + string(day(hwom_mod_date ),"99") format "x(10)" ",".
    end.
    put 
    """" hwom_chk_userid   """," .
    if hwom_chk_date  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwom_chk_date ),"9999") + "-" + string(month(hwom_chk_date ),"99") + "-" + string(day(hwom_chk_date ),"99") format "x(10)" ",".
    end.
    put
    """" hwom_aud_userid   """," .
    if hwom_aud_date  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwom_aud_date ),"9999") + "-" + string(month(hwom_aud_date ),"99") + "-" + string(day(hwom_aud_date ),"99") format "x(10)" ",".
    end.
    put
    """" hwom_prog   format "x(12)" """," 
    """" hwom_user1        """," 
    """" hwom_user2        """," 
    """" hwom__chr01       """," 
    """" hwom__chr02       """," 
    """" hwom__chr03       """," 
    """" hwom__chr04       """," 
    """" hwom__chr05       """," .
    if hwom__dte01  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwom__dte01 ),"9999") + "-" + string(month(hwom__dte01 ),"99") + "-" + string(day(hwom__dte01),"99") format "x(10)" ",".
    end.
    if hwom__dte02  = ? then do:
        put ",".
    end.
    else  do:
        put string(year(hwom__dte02 ),"9999") + "-" + string(month(hwom__dte02 ),"99") + "-" + string(day(hwom__dte02),"99") format "x(10)" ",".
    end.
    put
         hwom__dec01    format "->>>>>>>>9.9<<<<<<" ","
         hwom__dec02    format "->>>>>>>>9.9<<<<<<" ","
         hwom__dec03    format "->>>>>>>>9.9<<<<<<" ","
         hwom__dec04    format "->>>>>>>>9.9<<<<<<" ","
         hwom__dec05    format "->>>>>>>>9.9<<<<<<" ","
         hwom__int01    format "->>>>>>>>9" "," 
         hwom__int02    format "->>>>>>>>9" "," 
         hwom__int03    format "->>>>>>>>9" "," 
         hwom__int04    format "->>>>>>>>9" "," 
         hwom__int05    format "->>>>>>>>9" "," 
    """" hwom__log01       """," 
    """" hwom__log02       """" 
    .
    put skip.

END.
OUTPUT CLOSE.


